/* tagsCreator.js ***   gubhugreyot *** sept 2012 */
var tipuanUrl = "http://gubhugreyot.blogspot.com/";
var edButtons = new Array();
var edLinks = new Array();
var edOpenTags = new Array();

function edButton(f, e, c, b, a, d) {
    this.id = f;
    this.display = e;
    this.tagStart = c;
    this.tagEnd = b;
    this.access = a;
    this.open = d
}
edButtons.push(new edButton("ed_gr", "", "", "", "", ""));
edButtons.push(new edButton("ed_b", "b", "<b>", "</b>", "b"));
edButtons.push(new edButton("ed_strong", "strong", "<strong>", "</strong>", "strong"));
edButtons.push(new edButton("ed_i", "i", "<i>", "</i>", "i"));
edButtons.push(new edButton("ed_em", "em", "<em>", "</em>", "em"));
edButtons.push(new edButton("ed_span", "span", "<span>", "</span>", "span"));
edButtons.push(new edButton("ed_div", "div", "<div>", "</div>", "div"));
edButtons.push(new edButton("ed_gr", "id", ' id=""', ' id=""'));
edButtons.push(new edButton("ed_gr", "class", ' class=""', ' class=""'));
edButtons.push(new edButton("ed_p", "p", "<p>", "</p>\n", "p"));
edButtons.push(new edButton("ed_h1", "h1", "<h1>", "</h1>\n", "1"));
edButtons.push(new edButton("ed_h2", "h2", "<h2>", "</h2>\n", "2"));
edButtons.push(new edButton("ed_h3", "h3", "<h3>", "</h3>\n", "3"));
edButtons.push(new edButton("ed_h4", "h4", "<h4>", "</h4>\n", "4"));
edButtons.push(new edButton("ed_h5", "h5", "<h5>", "</h5>\n", "5"));
edButtons.push(new edButton("ed_h6", "h6", "<h6>", "</h6>\n", "6"));
edButtons.push(new edButton("ed_u", "u", "<u>", "</u>\n", "u"));
edButtons.push(new edButton("ed_ul", "ul", "<ul>\n", "</ul>\n", "u"));
edButtons.push(new edButton("ed_ol", "ol", "<ol>\n", "</ol>\n", "o"));
edButtons.push(new edButton("ed_li", "li", "\t<li>", "</li>\n", "l"));
edButtons.push(new edButton("ed_bQuote", "bQuote", "<blockquote>", "</blockquote>", "q"));
edButtons.push(new edButton("ed_pre", "pre", "<pre>", "</pre>"));
edButtons.push(new edButton("ed_code", "code", "<code>", "</code>", "c"));
edButtons.push(new edButton("ed_table", "table", "<table>\n<tbody>", "</tbody>\n</table>\n"));
edButtons.push(new edButton("ed_tr", "tr", "\t<tr>\n", "\n\t</tr>\n"));
edButtons.push(new edButton("ed_td", "td", "\t\t<td>", "</td>\n"));
edButtons.push(new edButton("ed_dl", "dl", "<dl>\n", "</dl>\n"));
edButtons.push(new edButton("ed_dt", "dt", "\t<dt>", "</dt>\n"));
edButtons.push(new edButton("ed_dd", "dd", "\t<dd>", "</dd>\n"));
edButtons.push(new edButton("ed_form", "form", "<form>\n\n", "</form>\n", "form"));
edButtons.push(new edButton("ed_but", "button", "<button>", "</button>", "but"));
edButtons.push(new edButton("ed_gr", "<br />", "<br />\n", "<br />\n", "br"));
edButtons.push(new edButton("ed_gr", "Clear", '<div style="clear:both;"></div>\n', '<div style="clear:both;"></div>\n', "Clear"));
edButtons.push(new edButton("ed_gr", "style-css", '<style type="text/css">\n\n</style>\n', '<style type="text/css">\n\n</style>\n'));
edButtons.push(new edButton("ed_gr", "link-css", '<link href="" rel="stylesheet" type="text/css" />\n', '<link href=".../style.css" rel="stylesheet" type="text/css" />\n'));
edButtons.push(new edButton("ed_gr", "js-tag", '<script type="text/javascript">\n\n<\/script>\n', '<script type="text/javascript">\n\n<\/script>\n'));
edButtons.push(new edButton("ed_gr", "link-js", '<script src=".../javascript.js" type="text/javascript"><\/script>\n', '<script src=".../javascript.js" type="text/javascript"><\/script>\n'));
edButtons.push(new edButton("ed_gr", 'cDATA', '//<![CDATA[\n\n//]]>', '<!--\n\n//-->', 'cDATA'));
edButtons.push(new edButton("ed_gr", "img-tag", '<img src=".../image.jpg" width="" height="" border="0" />', '<img src=".../image.jpg" width="" height="" border="0" />'));
edButtons.push(new edButton("ed_link", "link", "", "</a>", "a"));
edButtons.push(new edButton("ed_ext_link", "ext-link", "", "</a>", "e"));
edButtons.push(new edButton("ed_img", "img", "", "", "m", - 1));
var extendedStart = edButtons.length;
edButtons.push(new edButton("ed_ins", "ins", "<ins>", "</ins>"));
edButtons.push(new edButton("ed_del", "del", "<del>", "</del>"));
edButtons.push(new edButton("ed_nobr", "nobr", "<nobr>", "</nobr>"));
edButtons.push(new edButton("ed_gr", "html", '<!DOCTYPE html>\n<html>\n<head>\n<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">\n<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">\n<title>gubhugreyot....</title>\n\n\n</head>\n<body>\n\n\n</body>\n</html>', '<!DOCTYPE html>\n<html>\n<head>\n<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">\n<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">\n<title>gubhugreyot....</title>\n\n\n</head>\n<body>\n\n\n</body>\n</html>', "doctype"));
edButtons.push(new edButton("ed_gr", "css-IE", '<!--[if IE]>\n<style type="text/css">\n CSS here! (All IE)\n</style>\n<![endif]-->\n', '<!--[if IE]>\n/* All CSS  spesific in IE */\n<link href="all-IE.css" rel="stylesheet" type="text/css" />\n<![endif]-->\n', "CSS-IE"));
edButtons.push(new edButton("ed_gr", "IE 7", '<!--[if IE 7]>\n<style type="text/css">\n CSS IE 7 here! (Spesific in IE 7)\n Replace "7" with others spesific IE\n</style>\n<![endif]-->\n', '<!--[if IE 7]>\n/* Replace "7" with others spesific IE */\n<link href="spesific-IE-7.css" rel="stylesheet" type="text/css" />\n<![endif]-->\n', "IE 7"));
edButtons.push(new edButton("ed_gr", "IE8-IE6", '<!--[if lte IE 8]>\n<style type="text/css">\nCSS for IE-8, IE-7 and down\n</style>\n<![endif]-->\n', '<!--[if lte IE 8]>\n /* css for IE-8, IE 7 and down */\n<link href="IE-8-and-down.css" rel="stylesheet" type="text/css" />\n<![endif]-->', "IE8-IE6"));
edButtons.push(new edButton("ed_gr", "IE6-IE8", '<!--[if lte IE 6]>\n<style type="text/css">\ncss for IE-6, IE 7 and up\n</style>\n<![endif]-->\n', '<!--[if lte IE 6]>\n /* css for IE-6, IE 7 and up */\n<link href="IE-6-and-up.css" rel="stylesheet" type="text/css" />\n<![endif]-->', "IE6-IE8"));
edButtons.push(new edButton("ed_gr", "js-IE", '<!--[if IE]>\n<script type="text/javascript">\n javascript here! (All IE)\n<\/script>\n<![endif]-->\n', '<!--[if IE]>\n/* javascript spesific in IE */\n<script src="javascript-IE.js" type="text/javascript"><\/script>\n<![endif]-->\n', "CSS-IE"));
edButtons.push(new edButton("ed_gr", "HOT", '<a href="http://gubhugreyot.blogspot.com/" target="_blank" title="Best blogger tutorials">gubhugreyot</a>\n', '<a href="http://bestbloggerhack.blogspot.com/" target="_blank" title="Best blogger tricks and hacks">Best Blogger Hacks</a>\n', "HOT"));

function edLink(c, a, b) {
    this.display = c;
    this.URL = a;
    if (!b) {
        b = 0
    }
    this.newWin = b
}
edLinks[edLinks.length] = new edLink("gubhugreyot.blogspot.com", "http://gubhugreyot.blogspot.com/");

function edShowButton(d, b, a) {
    if (b.access) {
        var c = ' accesskey = "' + b.access + '"'
    } else {
        var c = ""
    }
    switch (b.id) {
    case "ed_img":
        document.write('<input type="button" id="' + b.id + "_" + d + '" ' + c + ' class="ed_button" onclick="edInsertImage(\'' + d + '\');" value="' + b.display + '" />');
        break;
    case "ed_link":
        document.write('<input type="button" id="' + b.id + "_" + d + '" ' + c + ' class="ed_button" onclick="edInsertLink(\'' + d + "', " + a + ');" value="' + b.display + '" />');
        break;
    case "ed_ext_link":
    case "ed_ext_link":
        document.write('<input type="button" id="' + b.id + "_" + d + '" ' + c + ' class="ed_button" onclick="edInsertExtLink(\'' + d + "', " + a + ');" value="' + b.display + '" />');
        break;
    case "ed_footnote":
        document.write('<input type="button" id="' + b.id + "_" + d + '" ' + c + ' class="ed_button" onclick="edInsertFootnote(\'' + d + '\');" value="' + b.display + '" />');
        break;
    case "ed_via":
        document.write('<input type="button" id="' + b.id + "_" + d + '" ' + c + ' class="ed_button" onclick="edInsertVia(\'' + d + '\');" value="' + b.display + '" />');
        break;
    default:
        document.write('<input type="button" id="' + b.id + "_" + d + '" ' + c + ' class="ed_button" onclick="edInsertTag(\'' + d + "', " + a + ');" value="' + b.display + '"  />');
        break
    }
}
function edShowLinks() {
    var a = '<select onchange="edQuickLink(this.options[this.selectedIndex].value, this);"><option value="-1" selected>(Quick Links)</option>';
    for (i = 0; i < edLinks.length; i++) {
        a += '<option value="' + i + '">' + edLinks[i].display + "</option>"
    }
    a += "</select>";
    document.write(a)
}
function edAddTag(b, a) {
    if (edButtons[a].tagEnd != "") {
        edOpenTags[b][edOpenTags[b].length] = a;
        document.getElementById(edButtons[a].id + "_" + b).value = "/" + document.getElementById(edButtons[a].id + "_" + b).value
    }
}
function edRemoveTag(b, a) {
    for (i = 0; i < edOpenTags[b].length; i++) {
        if (edOpenTags[b][i] == a) {
            edOpenTags[b].splice(i, 1);
            document.getElementById(edButtons[a].id + "_" + b).value = document.getElementById(edButtons[a].id + "_" + b).value.replace("/", "")
        }
    }
}
function edCheckOpenTags(c, b) {
    var a = 0;
    for (i = 0; i < edOpenTags[c].length; i++) {
        if (edOpenTags[c][i] == b) {
            a++
        }
    }
    if (a > 0) {
        return true
    } else {
        return false
    }
}
function edCloseAllTags(b) {
    var a = edOpenTags[b].length;
    for (o = 0; o < a; o++) {
        edInsertTag(b, edOpenTags[b][edOpenTags[b].length - 1])
    }
}
function edQuickLink(c, d) {
    if (c > -1) {
        var b = "";
        if (edLinks[c].newWin == 1) {
            b = ' target="_blank"'
        }
        var a = '<a href="' + edLinks[c].URL + '"' + b + ">" + edLinks[c].display + "</a>";
        d.selectedIndex = 0;
        edInsertContent(edCanvas, a)
    } else {
        d.selectedIndex = 0
    }
}
function edSpell(e) {
    myField = document.getElementById(e);
    var d = "";
    if (document.selection) {
        myField.focus();
        var c = document.selection.createRange();
        if (c.text.length > 0) {
            d = c.text
        }
    } else {
        if (myField.selectionStart || myField.selectionStart == "0") {
            var b = myField.selectionStart;
            var a = myField.selectionEnd;
            if (b != a) {
                d = myField.value.substring(b, a)
            }
        }
    }
    if (d == "") {
        d = prompt('Enter the name of a woman and then click "OK":', "")
    }
    if (d != "") {
        window.open(tipuanUrl)
    }
}
function edToolbar(a) {
    document.write('<span id="ed_toolbar_' + a + '"><span>');
    for (i = 0; i < extendedStart; i++) {
        edShowButton(a, edButtons[i], i)
    }
    if (edShowExtraCookie()) {
        document.write('<input type="button" id="ed_spell_' + a + '" class="ed_button" onclick="edSpell(\'' + a + '\');" value="BEST" />')
    } else {
        document.write('<input type="button" id="ed_close_' + a + '" class="ed_button" onclick="edCloseAllTags(\'' + a + '\');" value="/>" /><input type="button" id="ed_spell_' + a + '" class="ed_button" onclick="edSpell(\'' + a + '\');" value="BEST" /><input type="button" id="ed_extra_show_' + a + '" class="ed_button" onclick="edShowExtra(\'' + a + '\')" value="&raquo;" /></span><br /><span id="ed_extra_buttons_' + a + '" style="display: block;"><input type="button" id="ed_extra_hide_' + a + '" class="ed_button" onclick="edHideExtra(\'' + a + '\');" value="&laquo;" />')
    }
    for (i = extendedStart; i < edButtons.length; i++) {
        edShowButton(a, edButtons[i], i)
    }
    document.write("</span>");
    document.write("</span>");
    edOpenTags[a] = new Array()
}
function edShowExtra(a) {
    document.getElementById("ed_extra_show_" + a).style.visibility = "hidden";
    document.getElementById("ed_extra_buttons_" + a).style.display = "block";
    edSetCookie("js_quicktags_extra", "show", new Date("December 31, 2100"))
}
function edHideExtra(a) {
    document.getElementById("ed_extra_buttons_" + a).style.display = "none";
    document.getElementById("ed_extra_show_" + a).style.visibility = "visible";
    edSetCookie("js_quicktags_extra", "hide", new Date("December 31, 2100"))
}
function edInsertTag(e, c) {
    myField = document.getElementById(e);
    if (document.selection) {
        myField.focus();
        sel = document.selection.createRange();
        if (sel.text.length > 0) {
            sel.text = edButtons[c].tagStart + sel.text + edButtons[c].tagEnd
        } else {
            if (!edCheckOpenTags(e, c) || edButtons[c].tagEnd == "") {
                sel.text = edButtons[c].tagStart;
                edAddTag(e, c)
            } else {
                sel.text = edButtons[c].tagEnd;
                edRemoveTag(e, c)
            }
        }
        myField.focus()
    } else {
        if (myField.selectionStart || myField.selectionStart == "0") {
            var b = myField.selectionStart;
            var a = myField.selectionEnd;
            var f = a;
            var d = myField.scrollTop;
            if (b != a) {
                myField.value = myField.value.substring(0, b) + edButtons[c].tagStart + myField.value.substring(b, a) + edButtons[c].tagEnd + myField.value.substring(a, myField.value.length);
                f += edButtons[c].tagStart.length + edButtons[c].tagEnd.length
            } else {
                if (!edCheckOpenTags(e, c) || edButtons[c].tagEnd == "") {
                    myField.value = myField.value.substring(0, b) + edButtons[c].tagStart + myField.value.substring(a, myField.value.length);
                    edAddTag(e, c);
                    f = b + edButtons[c].tagStart.length
                } else {
                    myField.value = myField.value.substring(0, b) + edButtons[c].tagEnd + myField.value.substring(a, myField.value.length);
                    edRemoveTag(e, c);
                    f = b + edButtons[c].tagEnd.length
                }
            }
            myField.focus();
            myField.selectionStart = f;
            myField.selectionEnd = f;
            myField.scrollTop = d
        } else {
            if (!edCheckOpenTags(e, c) || edButtons[c].tagEnd == "") {
                myField.value += edButtons[c].tagStart;
                edAddTag(e, c)
            } else {
                myField.value += edButtons[c].tagEnd;
                edRemoveTag(e, c)
            }
            myField.focus()
        }
    }
}
function edInsertContent(e, c) {
    myField = document.getElementById(e);
    if (document.selection) {
        myField.focus();
        sel = document.selection.createRange();
        sel.text = c;
        myField.focus()
    } else {
        if (myField.selectionStart || myField.selectionStart == "0") {
            var b = myField.selectionStart;
            var a = myField.selectionEnd;
            var d = myField.scrollTop;
            myField.value = myField.value.substring(0, b) + c + myField.value.substring(a, myField.value.length);
            myField.focus();
            myField.selectionStart = b + c.length;
            myField.selectionEnd = b + c.length;
            myField.scrollTop = d
        } else {
            myField.value += c;
            myField.focus()
        }
    }
}
function edInsertLink(d, c, b) {
    myField = document.getElementById(d);
    if (!b) {
        b = "http://"
    }
    if (!edCheckOpenTags(d, c)) {
        var a = prompt("Enter the URL", b);
        if (a) {
            edButtons[c].tagStart = '<a href="' + a + '">';
            edInsertTag(d, c)
        }
    } else {
        edInsertTag(d, c)
    }
}
function edInsertExtLink(d, c, b) {
    myField = document.getElementById(d);
    if (!b) {
        b = "http://"
    }
    if (!edCheckOpenTags(d, c)) {
        var a = prompt("Enter the URL", b);
        if (a) {
            edButtons[c].tagStart = '<a href="' + a + '" rel="external">';
            edInsertTag(d, c)
        }
    } else {
        edInsertTag(d, c)
    }
}
function edInsertImage(b) {
    myField = document.getElementById(b);
    var a = prompt("Enter the URL of the image", "http://");
    if (a) {
        a = '<img src="' + a + '" alt="' + prompt("Enter a description of the image", "") + '" />';
        edInsertContent(b, a)
    }
}
function edInsertFootnote(b) {
    myField = document.getElementById(b);
    var h = prompt("Enter the footnote:", "");
    if (!h || h == "") {
        return false
    }
    var a = new Date;
    var f = "fn" + a.getTime();
    var j = myField.value.indexOf('<ol class="footnotes">');
    if (j != -1) {
        var d = myField.value.substring(0, j);
        var c = myField.value.substring(j, myField.value.length);
        var e = countInstances(c, '<li id="') + 1
    } else {
        var e = 1
    }
    var e = '<sup><a href="#' + f + 'n" id="' + f + '" class="footnote">' + e + "</a></sup>";
    edInsertContent(b, e);
    if (j != -1) {
        d = myField.value.substring(0, j + e.length);
        c = myField.value.substring(j + e.length, myField.value.length)
    } else {
        var d = myField.value;
        var c = '\n\n<ol class="footnotes">\n</ol>\n'
    }
    var g = '<li id="' + f + 'n">' + h + ' [<a href="#' + f + '">back</a>]</li>\n</ol>';
    myField.value = d + c.replace("</ol>", g)
}
function countInstances(a, c) {
    var b = a.split(c);
    return b.length - 1
}
function edInsertVia(b) {
    myField = document.getElementById(b);
    var a = prompt("Enter the URL of the source link", "http://");
    if (a) {
        a = '(Thanks <a href="' + a + '" rel="external">' + prompt("Enter the name of the source", "") + "</a>)";
        edInsertContent(b, a)
    }
}
function edSetCookie(b, d, a, e, c) {
    document.cookie = b + "=" + escape(d) + ((a) ? "; expires=" + a.toGMTString() : "") + ((e) ? "; path=" + e : "") + ((c) ? "; domain=" + c : "")
}
function edShowExtraCookie() {
    var c = document.cookie.split(";");
    for (var b = 0; b < c.length; b++) {
        var a = c[b];
        while (a.charAt(0) == " ") {
            a = a.substring(1, a.length)
        }
        if (a.indexOf("js_quicktags_extra") == 0) {
            if (a.substring(19, a.length) == "show") {
                return true
            } else {
                return false
            }
        }
    }
    return false
};